@extends('develop.layoutEdit')

@section('css')
    <link rel="stylesheet" type="text/css" href="/static/libs/uploadify/uploadify.css?v=20170509">
    <style>
        .uploadify {
            float: left;
            margin-right: 10px;
        }
         .layer-go-back{
             display:none;
         }
    </style>
@endsection

@section('title')
    <li class="cur">
        <span>商城设置</span>
    </li>
@endsection

@section('content')

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>开启微店长：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="open_shopowner" class="open_shopowner" value="1" title="是" lay-filter="check" @if( isset($configure['open_shopowner']) && $configure['open_shopowner'] == 1 ) checked @endif>
                <input type="radio" name="open_shopowner" class="open_shopowner" value="0" title="否" lay-filter="nocheck" @if( !isset($configure['open_shopowner']) || $configure['open_shopowner'] == 0 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group" id="fx_domain_url" @if( !isset($configure['open_shopowner']) || $configure['open_shopowner'] == 0 ) style="display: none;" @endif>
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>微分销域名：</label>
        <div class="col-sm-5" >
            <input type="text" class="form-control" name="fx_domain_url" value="{{ $configure['fx_domain_url'] or ''}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>验证码方式：</label>
        <div class="col-sm-9" >
            <div class="layui-form">
                <input type="radio" name="yzm_style"  value="1" title="仅字母" @if( !isset($configure['yzm_style']) || $configure['yzm_style'] == 1 ) checked @endif>
                <input type="radio" name="yzm_style"  value="2" title="仅数字" @if( isset($configure['yzm_style']) && $configure['yzm_style'] == 2 ) checked @endif>
                <input type="radio" name="yzm_style"  value="3" title="字母加数字" @if( isset($configure['yzm_style']) && $configure['yzm_style'] == 3 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red mr5">*</span>微电汇自营平台：</label>
        <div class="col-sm-9">
            <div class="layui-form">
            <input type="checkbox" name="support_platform" class="radio-inline platefrom-1" value="1" title="PC" @if( !isset($configure['support_platform']) || in_array(1,$configure['support_platform'])) checked @endif>
            <input type="checkbox" name="support_platform" class="radio-inline platefrom-2" value="2" title="WAP" @if(in_array(2,$configure['support_platform']))checked @endif>
            <input type="checkbox" name="support_platform" class="radio-inline platefrom-3" value="3" title="PAD" @if(in_array(3,$configure['support_platform']))checked @endif>
            <input type="checkbox" name="support_platform" class="radio-inline platefrom-4" value="4" title="APP" @if(in_array(4,$configure['support_platform']))checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>大数据导出地址：</label>
        <div class="col-sm-5" >
            <input type="text" class="form-control" id="multi_export_url" name="multi_export_url" value="{{ $configure['multi_export_url'] or ''}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>商城域名：</label>
        <div class="col-sm-5" >
            <input type="text" class="form-control" id="domain_url" name="domain_url" value="{{ $configure['domain_url'] or ''}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>商城名称：</label>
        <div class="col-sm-5" >
            <input type="text" class="form-control" id="website_name" name="website_name" value="{{ $configure['website_name'] or ''}}" >
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>商城LOGO：</label>
        <div class="col-sm-5">
            <input type="file"  id="update_logo_{{ $function_id }}" style="float: left;"/>
            <button type="button" class="btn btn-default" id="pic_{{ $function_id }}" onclick="plugin.option_photo({{ $function_id }});">从图片库选择</button>

            <div id="logo_img_box_{{ $function_id }}" style="margin-top: 5px;">
                @if( isset($configure['website_logo_url']) )
                <img style="width: 200px;height: 100px;" src="{{ $configure['website_logo_url'] or ''}}">
                <a href="javascript: void(0);" id="del_log_img_{{ $function_id }}">删除</a>
                @endif
            </div>
            <input type="hidden" name="website_logo_url" id="website_logo_url" value="{{ $configure['website_logo_url'] or ''}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <input type="hidden" name="function_id" id="function_id" value="{{ $function_id or ''}}">
            <input type="button"  value="保存" onclick="func.edit();" class="btn btn-success" >
        </div>
    </div>

@endsection
@section('js')
    <script type="text/javascript" src="/static/libs/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="/static/ebsig/jquery.photo.min.js?v=20151219"></script>
    <script>
        layui.use(['form'], function(){
            var form = layui.form();
            form.on('radio(check)', function(data){
                if ( this.checked ) {
                    $('#fx_domain_url').show();
                }
            });
            form.on('radio(nocheck)', function(data){
                if ( this.checked ) {
                    $('#fx_domain_url').hide();
                }
            });
        });

    $(document).on('click', 'a[id^="del_log_img_"]', function() {
            var key = $(this).attr('id').replace('del_log_img_', '');
            $('#logo_img_box_' + key).html('').hide();
            $('#' + key).val('');
        });

        var func = {

            //保存
            edit:function(){

                var msg = '' ;
                var configure = E.getFormValues('edit-form') ;

                if( E.isEmpty( configure.function_id ) || !E.isInt( configure.function_id ) ) {
                    msg += '参数错误<br/>';
                }

                var reg = /http:\/\/.+/i;
                if ( configure.open_shopowner == 1 ) {
                    if( E.isEmpty( configure.fx_domain_url ) ) {
                        msg += '请填写微分销域名<br/>';
                    } else if ( !reg.test( configure.fx_domain_url ) ) {
                        msg += '微分销域名必须是正确的URL(以http://格式开头)<br/>';
                    }
                }

                if( !$('input[name="support_platform"]').is(':checked') ){
                    msg += '请选择微电汇自营平台<br>';
                }

                if( E.isEmpty( configure.multi_export_url ) ) {
                    msg += '请填写大数据地址<br/>';
                } else if ( !reg.test( configure.multi_export_url ) ) {
                    msg += '大数据地址必须是正确的URL(以http://格式开头)<br/>';
                }

                if( E.isEmpty( configure.domain_url ) ) {
                    msg += '请填写商城域名<br/>';
                } else if ( !reg.test( configure.domain_url ) ) {
                    msg += '商城域名必须是正确的URL(以http://格式开头)<br/>';
                }

                if( E.isEmpty( configure.website_name ) ) {
                    msg += '请填写商城名称<br/>';
                }

                var logo_url = $('#logo_img_box_{{$function_id}}').find("img").attr('src');
                if(E.isEmpty(logo_url)){
                    msg += '请上传商城LOGO<br/>';
                }

                if( msg ) {
                    layer.alert( msg , { icon:2 });
                    return false ;
                }
                configure.website_logo_url = logo_url;
                layer.confirm("您确认保存该设置吗？",{icon:3,offset:'50px'}, function ( index ){
                    layer.close( index );
                    E.ajax( {
                        type:'get',
                        url: '/lar/develop/function/store/'+function_id,
                        data: configure,
                        dataType:'json',
                        // 返回值判断
                        success: function ( obj ){

                            if ( obj.code == 200 ) {
                                layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                            } else {
                                layer.alert( obj.message , { icon: 2 } ) ;
                            }
                        }
                    } ) ;
                });
            }

        };

        var plugin = {

            index : 0 ,

            //选择图片插件
            option_photo: function( index  ) {

                plugin.index = index  ;

                layer.open({
                    title: '选择图片',
                    type: 2,
                    scrollbar: false,
                    area: ['100%', '100%'],
                    content: '/postsystem/app/plugin/photoPlugin.pscript?operFlg=1'
                });

            },

            photo: function ( data ) {
                $('#logo_img_box_'+ plugin.index ).html('<img style="width:200px;height:100px;" src="' + data.link + '"> <a href="javascript: void(0);"  id="del_log_img_' + plugin.index + '">删除</a>').show();
                $('#wechat_pic_'+ plugin.index).val( data.link );
            }

        } ;

        $(window).ready(function() {

            //上传控件
            $("input[id^='update_logo_']").uploadify({
                buttonText    :  '<div>上传图片</div>',
                height        : 35,
                swf           : '/static/libs/uploadify/uploadify.swf',
                uploader      : '/external/upload.php?t=photo&group_id=1',
                width         : 120,
                onUploadSuccess: function(file, data) {
                    data = eval('('+data+')');
                    var key = $(this)[0]['settings']['id'].replace('update_logo_',"");
                    var url = data.url;

                    $('#logo_img_box_' + key).html('<img style="width:200px;height:100px;" src="' + url + '"> <a href="javascript: void(0);" id="del_log_img_' + key + '">删除</a>').show();
                    $('#' + key).val(url);
                }
            });

        });

    </script>
@endsection
